﻿Option Strict On
Option Explicit On 
Imports System.IO
Imports IP.Core.IPCommon
Imports IP.Core.IPException
Imports IP.Core.IPUserService
Imports IP.Core.IPData
Imports IP.Core.IPBusinessService
Imports IP.Core.IPDataControl



Public Class f101_Dang_Nhap_ELC
    Inherits System.Windows.Forms.Form

#Region "Nhiệm vụ của class"
    '***************************************************
    '* LOGIN - vào hệ thống   & setup application context
    '*     
    '***************************************************
#End Region

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        FormatForm()

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents m_txtMatKhau As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents m_txtTenTruyNhap As System.Windows.Forms.TextBox
    Friend WithEvents ImageList As System.Windows.Forms.ImageList
    Friend WithEvents m_cboDataBase As System.Windows.Forms.ComboBox
    Friend WithEvents m_lbl_msg As System.Windows.Forms.Label
    Friend WithEvents m_btnOK As SIS.Controls.Button.SiSButton
    Friend WithEvents m_btnCancel As SIS.Controls.Button.SiSButton
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents m_chk_save_password As System.Windows.Forms.CheckBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(f101_Dang_Nhap_ELC))
        Me.ImageList = New System.Windows.Forms.ImageList(Me.components)
        Me.m_txtMatKhau = New System.Windows.Forms.TextBox
        Me.m_cboDataBase = New System.Windows.Forms.ComboBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.m_txtTenTruyNhap = New System.Windows.Forms.TextBox
        Me.m_lbl_msg = New System.Windows.Forms.Label
        Me.m_btnOK = New SIS.Controls.Button.SiSButton
        Me.m_btnCancel = New SIS.Controls.Button.SiSButton
        Me.m_chk_save_password = New System.Windows.Forms.CheckBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label6 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label7 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'ImageList
        '
        Me.ImageList.ImageStream = CType(resources.GetObject("ImageList.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImageList.TransparentColor = System.Drawing.Color.Transparent
        Me.ImageList.Images.SetKeyName(0, "")
        Me.ImageList.Images.SetKeyName(1, "")
        '
        'm_txtMatKhau
        '
        Me.m_txtMatKhau.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.m_txtMatKhau.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.m_txtMatKhau.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.m_txtMatKhau.Location = New System.Drawing.Point(108, 121)
        Me.m_txtMatKhau.MaxLength = 25
        Me.m_txtMatKhau.Name = "m_txtMatKhau"
        Me.m_txtMatKhau.PasswordChar = Global.Microsoft.VisualBasic.ChrW(42)
        Me.m_txtMatKhau.Size = New System.Drawing.Size(196, 22)
        Me.m_txtMatKhau.TabIndex = 3
        '
        'm_cboDataBase
        '
        Me.m_cboDataBase.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.m_cboDataBase.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.m_cboDataBase.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.m_cboDataBase.ItemHeight = 15
        Me.m_cboDataBase.Items.AddRange(New Object() {"HOU.TOPICA", "DTU.TOPICA"})
        Me.m_cboDataBase.Location = New System.Drawing.Point(108, 153)
        Me.m_cboDataBase.Name = "m_cboDataBase"
        Me.m_cboDataBase.Size = New System.Drawing.Size(215, 23)
        Me.m_cboDataBase.TabIndex = 9
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.Color.Transparent
        Me.Label3.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.ForeColor = System.Drawing.Color.DarkRed
        Me.Label3.Location = New System.Drawing.Point(9, 153)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(92, 21)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "Cơ sở dữ liệu:"
        Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.Color.Transparent
        Me.Label2.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.Color.DarkRed
        Me.Label2.Location = New System.Drawing.Point(6, 121)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(95, 21)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Mật khẩu:"
        Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'm_txtTenTruyNhap
        '
        Me.m_txtTenTruyNhap.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.m_txtTenTruyNhap.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.m_txtTenTruyNhap.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.m_txtTenTruyNhap.Location = New System.Drawing.Point(108, 89)
        Me.m_txtTenTruyNhap.MaxLength = 12
        Me.m_txtTenTruyNhap.Name = "m_txtTenTruyNhap"
        Me.m_txtTenTruyNhap.Size = New System.Drawing.Size(196, 22)
        Me.m_txtTenTruyNhap.TabIndex = 1
        '
        'm_lbl_msg
        '
        Me.m_lbl_msg.BackColor = System.Drawing.Color.Yellow
        Me.m_lbl_msg.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.m_lbl_msg.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.m_lbl_msg.ForeColor = System.Drawing.Color.DarkRed
        Me.m_lbl_msg.Location = New System.Drawing.Point(0, 261)
        Me.m_lbl_msg.Name = "m_lbl_msg"
        Me.m_lbl_msg.Size = New System.Drawing.Size(409, 33)
        Me.m_lbl_msg.TabIndex = 11
        Me.m_lbl_msg.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'm_btnOK
        '
        Me.m_btnOK.AdjustImageLocation = New System.Drawing.Point(0, 0)
        Me.m_btnOK.BtnShape = SIS.Controls.Button.emunType.BtnShape.Rectangle
        Me.m_btnOK.BtnStyle = SIS.Controls.Button.emunType.XPStyle.[Default]
        Me.m_btnOK.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.m_btnOK.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.m_btnOK.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.m_btnOK.ImageIndex = 1
        Me.m_btnOK.ImageList = Me.ImageList
        Me.m_btnOK.Location = New System.Drawing.Point(104, 217)
        Me.m_btnOK.Name = "m_btnOK"
        Me.m_btnOK.Size = New System.Drawing.Size(97, 30)
        Me.m_btnOK.TabIndex = 13
        Me.m_btnOK.Text = "Đăng nhập"
        '
        'm_btnCancel
        '
        Me.m_btnCancel.AdjustImageLocation = New System.Drawing.Point(0, 0)
        Me.m_btnCancel.BtnShape = SIS.Controls.Button.emunType.BtnShape.Rectangle
        Me.m_btnCancel.BtnStyle = SIS.Controls.Button.emunType.XPStyle.[Default]
        Me.m_btnCancel.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.m_btnCancel.ForeColor = System.Drawing.SystemColors.ActiveCaption
        Me.m_btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.m_btnCancel.ImageIndex = 0
        Me.m_btnCancel.ImageList = Me.ImageList
        Me.m_btnCancel.Location = New System.Drawing.Point(223, 217)
        Me.m_btnCancel.Name = "m_btnCancel"
        Me.m_btnCancel.Size = New System.Drawing.Size(97, 30)
        Me.m_btnCancel.TabIndex = 14
        Me.m_btnCancel.Text = "Thoát (Esc)"
        '
        'm_chk_save_password
        '
        Me.m_chk_save_password.BackColor = System.Drawing.Color.Transparent
        Me.m_chk_save_password.Font = New System.Drawing.Font("Times New Roman", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.m_chk_save_password.ForeColor = System.Drawing.SystemColors.ActiveCaptionText
        Me.m_chk_save_password.Location = New System.Drawing.Point(108, 181)
        Me.m_chk_save_password.Name = "m_chk_save_password"
        Me.m_chk_save_password.Size = New System.Drawing.Size(19, 24)
        Me.m_chk_save_password.TabIndex = 15
        Me.m_chk_save_password.UseVisualStyleBackColor = False
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.Color.Transparent
        Me.Label1.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.Color.DarkRed
        Me.Label1.Location = New System.Drawing.Point(6, 89)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(95, 21)
        Me.Label1.TabIndex = 16
        Me.Label1.Text = "Tên truy nhập:"
        Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.Color.Transparent
        Me.Label5.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label5.ForeColor = System.Drawing.Color.DarkRed
        Me.Label5.Location = New System.Drawing.Point(130, 183)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(183, 21)
        Me.Label5.TabIndex = 17
        Me.Label5.Text = "Ghi nhớ mật khẩu đăng nhập"
        Me.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label6
        '
        Me.Label6.BackColor = System.Drawing.Color.Transparent
        Me.Label6.Font = New System.Drawing.Font("Times New Roman", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label6.ForeColor = System.Drawing.Color.DarkRed
        Me.Label6.Location = New System.Drawing.Point(199, 12)
        Me.Label6.Name = "Label6"
        Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.Yes
        Me.Label6.Size = New System.Drawing.Size(189, 14)
        Me.Label6.TabIndex = 18
        Me.Label6.Text = "Version: 1.6.8"
        Me.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label4.Font = New System.Drawing.Font("Times New Roman", 14.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.ForeColor = System.Drawing.Color.DarkRed
        Me.Label4.Location = New System.Drawing.Point(80, 26)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(236, 22)
        Me.Label4.TabIndex = 19
        Me.Label4.Text = "ĐĂNG NHẬP PHẦN MỀM"
        Me.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'Label7
        '
        Me.Label7.AutoSize = True
        Me.Label7.BackColor = System.Drawing.Color.Transparent
        Me.Label7.Font = New System.Drawing.Font("Times New Roman", 14.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label7.ForeColor = System.Drawing.Color.DarkRed
        Me.Label7.Location = New System.Drawing.Point(4, 53)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(390, 22)
        Me.Label7.TabIndex = 20
        Me.Label7.Text = "TỰ ĐỘNG HÓA NGHIỆP VỤ GIÁO VỤ 2012"
        Me.Label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight
        '
        'f101_Dang_Nhap_ELC
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.White
        Me.ClientSize = New System.Drawing.Size(409, 294)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.m_chk_save_password)
        Me.Controls.Add(Me.m_btnOK)
        Me.Controls.Add(Me.m_btnCancel)
        Me.Controls.Add(Me.m_txtMatKhau)
        Me.Controls.Add(Me.m_txtTenTruyNhap)
        Me.Controls.Add(Me.m_cboDataBase)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.m_lbl_msg)
        Me.Font = New System.Drawing.Font("Times New Roman", 8.0!)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Name = "f101_Dang_Nhap_ELC"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "M001-Dang nhap School Mangement"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region

#Region "PUBLIC INTERFACES"
    Public Sub displayLogin(ByRef o_Information As CLoginInformation_302, _
                            ByRef o_LoginResult As DialogResult)
        '*********************************************************************
        '* Hiện thị cửa sổ đăng nhập vào hệ thống
        '* Trả lại kết quả tùy theo kết quả đăng nhập. Có hai loại
        '* - Thành công : o_LoginResult = DialogResult.OK
        '* - Không thành công : o_LoginResult = DialogResult.Cancel
        '* - Tại đay không kiểm tra thông tin trong CSDL
        '*********************************************************************

        'Hiện thị cửa sổ
        o_LoginResult = DialogResult.Cancel
        Me.ShowDialog()
        o_LoginResult = Me.DialogResult
        If o_LoginResult = DialogResult.OK Then
            'phai lap trinh
            o_Information = New CLoginInformation_302(m_strUserName, m_strPassword, m_strDatabaseSchema)
        End If

    End Sub
#End Region

#Region "Data Structure"
    Private C_MSG_UserNamePWD_Not_Correct As String = "Username and password may not correct"
    Private C_MSG_User_Not_In_Use As String = "Username NOT IN USE"
    Private C_MSG_User_in_lock As String = "Username in lock"
    Private C_MSG_Connecting As String = "Kết nối vào máy chủ ...."
#End Region

#Region "Members"
    Private m_strUserName As String
    Private m_strPassword As String
    Private m_strDatabaseSchema As String
    Private m_StrLastUsername As String
    Private m_StrLastPassword As String
    Private m_StrSaveYN As String
#End Region

#Region "Private methods"
    Private Sub FormatForm()
        CControlFormat.setFormStyle(Me, IPFormStyle.FlashForm)
        Me.BackColor = Color.White
        Label1.BackColor = System.Drawing.Color.Transparent
        Label2.BackColor = System.Drawing.Color.Transparent
        Label3.BackColor = System.Drawing.Color.Transparent
        'Label4.BackColor = System.Drawing.Color.Transparent
        Label5.BackColor = System.Drawing.Color.Transparent
        Label6.BackColor = System.Drawing.Color.Transparent

        Label1.ForeColor = System.Drawing.Color.DarkRed
        Label2.ForeColor = System.Drawing.Color.DarkRed
        Label3.ForeColor = System.Drawing.Color.DarkRed
        'Label4.ForeColor = System.Drawing.Color.White
        Label5.ForeColor = System.Drawing.Color.DarkRed
        Label6.ForeColor = System.Drawing.Color.DarkRed
        '
        Me.Label4.Font = New System.Drawing.Font("Times New Roman", 14.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label4.ForeColor = System.Drawing.Color.DarkRed
        Me.Label7.Font = New System.Drawing.Font("Times New Roman", 14.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label7.ForeColor = System.Drawing.Color.DarkRed
        Me.Label4.BackColor = System.Drawing.Color.Transparent
        Me.Label7.BackColor = System.Drawing.Color.Transparent

        '
        m_lbl_msg.BackColor = System.Drawing.Color.Yellow
        Me.Label6.Text = "SCM.HOU." + DateTime.Today.ToString("yyyy.MMdd.HHmmss")
        Me.ShowInTaskbar = True
    End Sub

    Private Function ValidLogonData() As Boolean
        If Not CValidateTextBox.IsValid(Me.m_txtTenTruyNhap, DataType.StringType, allowNull.NO, False) Then
            BaseMessages.MsgBox_Warning(602)
            Return False
        End If

        If Not CValidateTextBox.IsValid(Me.m_txtMatKhau, DataType.StringType, allowNull.NO, False) Then
            BaseMessages.MsgBox_Warning(603)
            Return False
        End If
        Return True
    End Function
    Private Sub LoadDataBase()
        '  Load cac co so du lieu co the login duoc vao day
        '  Phai lay tu client side
        m_cboDataBase.Items.Clear()
        Dim v_simple_string_cbo As New IPSimpleStringComboBoxManager(m_cboDataBase)
        'v_simple_string_cbo.addItem(CApplicationContext.get_product_datasource(), "0- Chọn CSDL")
        v_simple_string_cbo.addItem(CApplicationContext.get_product_datasource(), "1- HOU.TOPICA")
        'v_simple_string_cbo.addItem(CApplicationContext.get_developer_datasource, "2- DTU.TOPICA")
        'If (CApplicationContext.get_run_mode() = "DEVELOP") Then
        'm_cboDataBase.SelectedIndex = 1
        'Else
        m_cboDataBase.SelectedIndex = 0
        'End If
    End Sub

    Private Sub set_connecting_status(ByVal i_str_connecting_status As String)
        m_lbl_msg.Text = i_str_connecting_status
        Me.Refresh()
    End Sub


    Private Function SubmitLogonIsOK() As Boolean
        Dim v_str_data_source As String
        Try
            '*********************************************************************   
            '*  Kiểm tra các trường trên màn hình
            '*********************************************************************
            If Not ValidLogonData() Then
                Return False
            Else
                set_connecting_status(C_MSG_Connecting)
                'If m_cboDataBase.SelectedIndex = 0 Then
                '    BaseMessages.MsgBox_Infor("Chọn CSDL")
                '    Return False
                'End If
                '' Lấy tham số CSDL
                'If m_cboDataBase.SelectedIndex = 1 Then
                '    v_str_data_source = "SCM"
                'Else
                '    v_str_data_source = "DTU"
                'End If
                v_str_data_source = System.Configuration.ConfigurationSettings.AppSettings("PRODUCT_DATASOURCE")
                CProvider.SetConnectionParameter( _
                    v_str_data_source, _
                    m_txtTenTruyNhap.Text, _
                    m_txtMatKhau.Text)
                'Set datasource
                CApplicationContext.set_DataSourceName(v_str_data_source)
                If CheckLoginStatus(m_txtTenTruyNhap.Text, m_txtMatKhau.Text) Then
                    If CheckAccount(m_txtTenTruyNhap.Text) = True Then
                        BaseMessages.MsgBox_Infor("Account đã bị khóa")
                        Return False
                    End If
                    Return True
                Else
                    Return False
                End If
            End If
        Catch v_ex As Exception
            Return False
        End Try

    End Function

    Private Sub setInitialFormLoad()
        Try
            GetFileContents("fms.dll")
            LoadDataBase()
        Catch v_ex As Exception
            Dim v_ErrHandler As CDBExceptionHandler = New CDBExceptionHandler(v_ex, New CDBClientDBExceptionInterpret)
            v_ErrHandler.showErrorMessage()
        End Try

    End Sub

    Private Function CheckLoginStatus(ByVal i_str_username As String, _
                                      ByVal i_str_pwd As String) As Boolean
        Try
            Dim v_str_login_status As String = New US_HT_PHAN_QUYEN_HE_THONG().check_login_status( _
                                    i_str_username, _
                                    i_str_pwd)
            If (v_str_login_status = US_HT_PHAN_QUYEN_HE_THONG.C_LOGIN_USER_NORMAL) Then
                Return True
            ElseIf (v_str_login_status = US_HT_PHAN_QUYEN_HE_THONG.C_LOGIN_USER_NOT_EXISTS) Then
                set_connecting_status(C_MSG_UserNamePWD_Not_Correct)
                Return False
            ElseIf (v_str_login_status = US_HT_PHAN_QUYEN_HE_THONG.C_LOGIN_USER_NOT_IN_USE) Then
                set_connecting_status(C_MSG_User_Not_In_Use)
                Return False
            ElseIf (v_str_login_status = US_HT_PHAN_QUYEN_HE_THONG.C_LOGIN_USER_IN_LOCK) Then
                set_connecting_status(C_MSG_User_in_lock)
                Return False
            Else
                System.Diagnostics.Debug.Assert(False, "Khong co truong hop ket qua kiem tra LOGIN the nay")
                Return False
            End If
        Catch v_e As Exception
            set_connecting_status("Error: " + v_e.Message)
            Return False
        End Try
    End Function
    Private Function CheckAccount(ByVal i_str_user_name As String) As Boolean
        Try
            Return New US_HT_NGUOI_SU_DUNG().check_lock_account(i_str_user_name)
        Catch
            Return False
        End Try
        Return False
    End Function
    Private Sub GetFileContents(ByVal i_FullPath As String, _
    Optional ByRef i_ErrInfo As String = "")
        Dim v_objReader As StreamReader
        Try
            v_objReader = New StreamReader(i_FullPath)
            m_StrSaveYN = v_objReader.ReadLine()
            If CIPConvert.ToBoolean(m_StrSaveYN) Then
                m_chk_save_password.Checked = True
                m_StrLastUsername = v_objReader.ReadLine()
                m_StrLastPassword = v_objReader.ReadLine()
                m_txtTenTruyNhap.Text = m_StrLastUsername
                m_txtMatKhau.Text = m_StrLastPassword
            Else
                m_chk_save_password.Checked = False
            End If
            v_objReader.Close()
        Catch Ex As Exception
            m_StrLastUsername = ""
            m_StrSaveYN = ""
            m_StrLastPassword = ""
        End Try
    End Sub
    Private Function SaveTextToFile( _
     ByVal i_FullPath As String, _
        Optional ByVal i_ErrInfo As String = "") As Boolean
        Dim v_Contents As String
        Dim v_bAns As Boolean = False
        Dim v_objReader As StreamWriter
        Try
            v_objReader = New StreamWriter(i_FullPath)
            If (m_chk_save_password.Checked) Then
                v_objReader.WriteLine("Y")
                v_objReader.WriteLine(m_txtTenTruyNhap.Text)
                v_objReader.WriteLine(m_txtMatKhau.Text)
            Else
                v_objReader.WriteLine("N")
                v_objReader.WriteLine("")
                v_objReader.WriteLine("")
            End If

            v_objReader.Close()
            v_bAns = True
        Catch Ex As Exception
            i_ErrInfo = Ex.Message
        End Try
        Return v_bAns
    End Function
#End Region
    '    EVENTS HANDER
    '
    Private Sub f101_Dang_Nhap_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.KeyPreview = True
        Try
            setInitialFormLoad()
            AddHandler m_btnOK.Click, AddressOf m_btnOK_Click
            AddHandler m_btnCancel.Click, AddressOf m_btnCancel_Click
        Catch v_e As System.Exception
            CSystemLog_301.ExceptionHandle(v_e)
            Me.Close()
        End Try
    End Sub



    Private Sub m_btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        '**********************************************************************
        '*  Thoát ra không vào hệ thống nữa
        '********************************************************************
        Me.DialogResult = DialogResult.Cancel
        Me.Close()
    End Sub


    Private Function getDatabaseSchema() As String
        Return CIPConvert.ToStr(m_cboDataBase.SelectedValue)
    End Function

    Private Sub m_btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Try
            If (SubmitLogonIsOK()) Then
                ''' setting values
                m_strUserName = m_txtTenTruyNhap.Text
                m_strPassword = m_txtMatKhau.Text
                m_strDatabaseSchema = getDatabaseSchema()
                ' luu thong tin save password lai
                SaveTextToFile("fms.dll")
                ''' exit this window
                Me.DialogResult = DialogResult.OK
                Me.Close()
            End If

        Catch ex As Exception
            CSystemLog_301.ExceptionHandle(ex)
        End Try
    End Sub

    Private Sub f101_Dang_Nhap_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        Try
            Select Case e.KeyCode
                Case Keys.Escape
                    Me.m_btnCancel_Click(sender, e)
                Case Keys.Enter
                    Me.m_btnOK_Click(sender, e)
            End Select
        Catch ex As Exception
            CSystemLog_301.ExceptionHandle(ex)
        End Try
    End Sub


End Class